import { createSlice, type Slice } from "@reduxjs/toolkit";
import type { HomeViewSlice } from "../type/HomeViewSlice";
import type { MapData } from "../type/HomeView";

const homeViewSlice: Slice<HomeViewSlice> = createSlice({
  name: 'homeView',
  initialState: {
    mapData: localStorage.mapData ? JSON.parse(localStorage.mapData) : {} as MapData
  },
  reducers: {
    setMapData (state, action) {
      state.mapData = action.payload
      localStorage.mapData = JSON.stringify(action.payload)
    }
  }
})

export const { setMapData } = homeViewSlice.actions
export default homeViewSlice
